#include "stm32f10x.h"                  // Device header
#include "stdint.h"
#include "Delay.h"
#include "Key.h"


void Key_Init(void)
{
	RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE);
	
	GPIO_InitTypeDef gpioInitStruture;
	gpioInitStruture.GPIO_Mode = GPIO_Mode_IPU;
	gpioInitStruture.GPIO_Pin = GPIO_Pin_1 | GPIO_Pin_11;
	gpioInitStruture.GPIO_Speed = GPIO_Speed_50MHz;
	GPIO_Init(GPIOB, &gpioInitStruture);
	
	
}

uint8_t Key_GetNum(void)
{
	uint8_t KeyNum = 0;
	
	if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 0){
		Delay_ms(20);	//按键按下消抖
		while(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_1) == 0);
		Delay_ms(20);	//按键松开消抖
		KeyNum = 1;
	}
	
	if(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == 0){
		Delay_ms(20);	//按键按下消抖
		while(GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_11) == 0);
		Delay_ms(20);	//按键松开消抖
		KeyNum = 2;
	}
	
	return KeyNum;
}
